﻿using System;
using System.Windows.Forms;

namespace SuperTimeSync
{
    public partial class Main : Form
    {
        private DateTime DtTemp;
        private int sIndex = -1;

        public Main()
        {
            InitializeComponent();
        }

        private void Main_Load(object sender, EventArgs e)
        {
            label1.Text = DateTime.Now.ToString("F");
            comboBox1.SelectedIndex = 0;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            sIndex = comboBox1.SelectedIndex;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {            
            label2.Text = GetTime.DTime(sIndex, ref DtTemp);
            label2.Text = DtTemp.ToString("yyyy-MM-dd HH-mm-ss fff");
            label1.Text = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss fff");  //后抓取本机时间，减小网络延时带来的计算误差
            label3.Text = "误差 " + (DateTime.Now - DtTemp).ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (UpdateTime.SetDate(DtTemp))
                MessageBox.Show("同步成功");
            else
                MessageBox.Show("同步失败");
            label2.Text = DateTime.Now.ToString();
        }
    }
}